/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import ClasesGenerales.Tarifa;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author USER
 */
public class ClienteDO {

    PreparedStatement oPreparedStatement = null;
    ResultSet oResultSet = null;
    Connection oConnection = null;
    private String Esquema = "APP";

    private Connection getConnection() throws SQLException {
        Connection conn;
        //BDConexFactory fact = new BDConexFactory(dataSource);
        conn = BDConexFactory.getInstance().getConnection();
        return conn;
    }

    public List<Tarifa> BucarTarifa(String oTipoPax,
                                    String oClaseReserva,
                                    String oOrientacion) throws SQLException {

        Tarifa oTarifa = null;
        String oAuxCadenaClase = null;
        List<Tarifa> oListaTarifa = null;

        try {

            oConnection = getConnection();

            if (oClaseReserva.length() == 1) {
                oAuxCadenaClase = "AND TARIFAS.CO_CLASERESERVA = '" + oClaseReserva + "' ";
            } else {
                oAuxCadenaClase = "AND TARIFAS.CO_CLASERESERVA IN ('" + oClaseReserva.replaceAll("/", "','") + "')";
            }

            String sql = "SELECT * FROM " + Esquema + ".TARIFAS "
                    + "WHERE CO_TIPOPAX = '" + oTipoPax + "' "
                    + "AND TARIFAS.CO_ORIENTACION = '" + oOrientacion + "' "
                    + oAuxCadenaClase;

            oPreparedStatement = oConnection.prepareStatement(sql);
            oResultSet = oPreparedStatement.executeQuery();
            
            oListaTarifa = new ArrayList();
            while (oResultSet.next()) {

                oTarifa = new Tarifa();
                oTarifa.setCO_TIPOPAX(oResultSet.getString("CO_TIPOPAX"));
                oTarifa.setCO_CLASERESERVA(oResultSet.getString("CO_CLASERESERVA"));
                oTarifa.setCO_ORIENTACION(oResultSet.getString("CO_ORIENTACION"));
                oTarifa.setNU_NETO(oResultSet.getDouble("NU_NETO"));
                oTarifa.setNU_IMPUESTOS(oResultSet.getDouble("NU_IMPUESTOS"));
                
                oListaTarifa.add(oTarifa);

            }

        } catch (Exception e) {
        } finally {

            try {
                if (oResultSet != null) {
                    oResultSet.close();
                }
            } catch (SQLException e) {
                System.out.println("DAOArancel buscarArancelBD()"
                        + e.getMessage());

            } finally {

                try {
                    if (oPreparedStatement != null) {
                        oPreparedStatement.close();
                    }
                } catch (SQLException e) {
                    System.out.println("DAOArancel buscarArancelBD()"
                            + e.getMessage());

                }
                try {
                    if (oConnection != null) {
                        oConnection.close();
                        System.out.println("DAOArancel buscarArancelBD() cerrando conexion a  Base de Datos");

                    }
                } catch (SQLException e) {
                    System.out.println("DAOArancel buscarArancelBD()"
                            + e.getMessage());

                }

            }

            return oListaTarifa;

        }

    }
}
